#
x = 1
while x <= 3:
    print(x)
    x += 1
#
words = ['this', 'is', 'an', 'ex', 'parrot']
for word in words:
    print(word)

#
for number in range(1, 5):
    print(number)

#
d = {'x': 1, 'y': 2, 'z': 3}
for key in d:
    print(key, 'corresponds to', d[key])
# x corresponds to 1
# y corresponds to 2
# z corresponds to 3

# 并行迭代 zip
names = ['anne', 'beth', 'george', 'damon']
ages = [12, 45, 32, 102]

for name, age in zip(names, ages):
    print(name, age)
# anne 12
# beth 45
# george 32
# damon 102


# zip 按照少的截断
# [(0, 0), (1, 1), (2, 2)]
print(list(zip(range(3), range(1000))))

# 获取索引 enumerate
names = ['anne', 'beth', 'george', 'damon']
for index, name in enumerate(names):
    print(f'i={index},name={name}')
# i=0,name=anne
# i=1,name=beth
# i=2,name=george
# i=3,name=damon

# break
from math import sqrt

for n in range(99, 0, -1):
    root = sqrt(n)
    if root == int(root):
        print(n)
        break
# 81

# continue
from math import sqrt

for n in range(99, 0, -1):
    root = sqrt(n)
    if root == int(root):
        print(n, end=',')
        continue
print()  # 81,64,49,36,25,16,9,4,1,

# while
i = 3
while True:
    i -= 1
    print(i, end='->')
    if i == 0:
        break
print()
# 2->1->0->

# for else
# 整个for没有迭代结束就跳出，则调用else代码块
for n in range(99, 81, -1):
    root = sqrt(n)
    if root == int(root):
        print(n)
        break
else:
    print("没有找到")
# 没有找到


#
